package zengjin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zengjin.common.PageResponse;
import zengjin.common.R;
import zengjin.model.dto.interview.AddInterviewRequest;
import zengjin.model.dto.interview.PageInterviewRequest;
import zengjin.model.dto.interview.UpdateInterviewRequest;
import zengjin.model.en.Interview;
import zengjin.model.vo.interview.InterviewVO;
import zengjin.model.vo.interview.PageInterviewVO;
import zengjin.service.InterviewService;

/**
 * @author 19324
 */
@Tag(name = "面试相关接口")
@RestController
@RequestMapping("/interview")
@Slf4j
public class InterviewController {

    @Resource
    private InterviewService interviewService;


    //1.添加面试
    @Operation(summary = "添加面试")
    @PostMapping("/addInterview")
    public R<Boolean> addInterview(@RequestBody AddInterviewRequest addInterviewRequest) {
        //1.参数校验
        if (addInterviewRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        Boolean addInterviewResult = interviewService.addInterview(addInterviewRequest);
        if (!addInterviewResult) {
            return R.error(false, "添加面试失败");
        }
        return R.success(true, "添加面试成功");

    }

    //2.修改面试
    @Operation(summary = "修改面试")
    @PostMapping("/updateInterview")
    public R<Boolean> updateInterview(@RequestBody UpdateInterviewRequest updateInterview) {
        //1.参数校验
        if (updateInterview == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        Boolean updateInterviewResult = interviewService.updateInterview(updateInterview);
        if (!updateInterviewResult) {
            return R.error(false, "修改面试失败");
        }
        return R.success(true, "修改面试成功");
    }

    //3.分页查询面试信息
    @Operation(summary = "分页查询面试信息")
    @PostMapping("/pageInterview")
    public R<PageResponse<PageInterviewVO>> pageInterview(@RequestBody PageInterviewRequest pageInterviewRequest) {

        //1.参数校验
        if (pageInterviewRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        PageResponse<PageInterviewVO> pageInterviewResult = interviewService.pageInterview(pageInterviewRequest);
        if (pageInterviewResult == null) {
            return R.error(null, "查询面试信息失败");
        }
        return R.success(pageInterviewResult, "查询面试信息成功");
    }

    //4.查询面试详情根据面试id
    @Operation(summary = "查询面试详情根据面试id")
    @PostMapping("/getInterviewById")
    public R<InterviewVO> getInterviewById(Long interviewId,String checkType) {
        //1.参数校验
        if (interviewId == null||checkType == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        InterviewVO interviewVO = interviewService.getInterviewById(interviewId, checkType);
        if (interviewVO == null) {
            return R.error(null, "查询面试详情失败");
        }
        return R.success(interviewVO, "查询面试详情成功");
    }

    //5.修改面试状态
    @Operation(summary = "修改面试状态")
    @PostMapping("/updateInterviewStatus")
    public R<Boolean> updateInterviewStatus(Long interviewId,String interviewStatus){
        //1.参数校验
        if(interviewId == null|| interviewStatus==null){
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        Boolean updateInterviewStatusResult = interviewService.updateInterviewStatus(interviewId, interviewStatus);
        if (!updateInterviewStatusResult) {
            return R.error(false, "修改面试状态失败");
        }
        return R.success(true, "修改面试状态成功");
    }


}
